package viethp.mtrade.activities;

import viethp.mtrade.customactivities.ATabHaveGroup;
import viethp.mtrade.customactivities.ATabNearByGroup;
import viethp.mtrade.customactivities.ATabWantGroup;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

public class AMain extends TabActivity {
    /** Called when the activity is first created. */
	
	private TabHost tabHost;
	private int currentTab;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        setTabs();
		
		currentTab=getIntent().getIntExtra("CURRENT_TAB", 0);
		tabHost.setCurrentTab(currentTab);
    }
    
    private void setTabs() {
		addTab("Activity", R.drawable.btn_tab_activity, ATabActivity.class);
		addTab("I Want", R.drawable.btn_tab_want, ATabWantGroup.class);
		addTab("Nearby", R.drawable.btn_tab_nearby, ATabNearByGroup.class);
		addTab("I Have", R.drawable.btn_tab_have, ATabHaveGroup.class);
		addTab("Account", R.drawable.btn_tab_account, ATabAccount.class);
	
	}

	private void addTab(String labelId, int drawableId, Class<?> c) {
		tabHost = getTabHost();
		Intent intent = new Intent(this, c);
		TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);

		View tabIndicator = LayoutInflater.from(this).inflate(
				R.layout.tab_indicator, getTabWidget(), false);
		TextView title = (TextView) tabIndicator.findViewById(R.id.title);
		title.setText(labelId);
		ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
		icon.setImageResource(drawableId);

		spec.setIndicator(tabIndicator);
		spec.setContent(intent);
		tabHost.addTab(spec);
	}
}